package org.example.response;

public class RespnseResult<T> {
    private int code;
    private String msg;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public RespnseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public RespnseResult(ResultCode resultCode){
        this.code=resultCode.getCode();
        this.msg=resultCode.getMsg();
    }

    public RespnseResult(ResultCode resultCode,T data){
        this.code=resultCode.getCode();
        this.msg=resultCode.getMsg();
        this.data=data;
    }

    public static <T> RespnseResult<T> success(){
        return  new RespnseResult<T>(ResultCode.SUCCESS);
    }

    public static <T> RespnseResult<T> success(T data){
        return new RespnseResult<>(ResultCode.SUCCESS,data);
    }

    public static <T> RespnseResult<T> error(){
        return new RespnseResult<>(ResultCode.FAIL);
    }
    public static <T> RespnseResult<T> error(String msg){
        return new RespnseResult<>(ResultCode.FAIL.getCode(),msg);
    }
}
